package com.example.networkchangedemo;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * @author: njb
 * @date: 2022/2/16 17:00
 * @desc: 描述
 */
public class SpUtils {
    SharedPreferences sharedPreferences;
    private static final String name = "userName";

    private void initSp(Context context) {
        sharedPreferences = context.getSharedPreferences( "SharedPreferences", Activity.MODE_PRIVATE);
    }

    private void saveName(Context context) {
        SharedPreferences mSharedPreferences = context.getSharedPreferences("loginUser", Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = mSharedPreferences.edit();

        //editor.putString("user_name", editText.getText().toString());
        editor.commit();
    }

    public static String getSaveName(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("loginUser", Context.MODE_PRIVATE);
        String content = sharedPreferences.getString("user_name","");
       return content;
    }

    private void clearName(Context context) {
        SharedPreferences sp = context.getSharedPreferences("loginUser", Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.commit();
    }
}
